﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ex03.GarageLogic
{
    /// <summary>
    /// every vehicle own an EnergySource with r_MaxEnergy, k_MinEnergy and m_CurrentEnergy
    /// </summary>
    internal abstract class EnergySource
    {
        protected readonly float r_MaxEnergy = 0;
        private const float k_MinEnergy = 0; 
        protected float m_CurrentEnergy = 0;

        public EnergySource(float i_MaxEnergy)
        {
            r_MaxEnergy = i_MaxEnergy;
        }     

        public float CurrentEnergy
        {
            get { return m_CurrentEnergy; }
            set { m_CurrentEnergy = value; }
        }

        public float MaxEnergy
        {
            get { return r_MaxEnergy; }          
        }
        
        /// <summary>
        /// fill the energy source with i_EnergyToFill
        /// throw ValueOutOfRangeException if i_EnergyToFill smaller then 0 or if i_EnergyToFill + m_CurrentEnergy bigger then r_MaxEnergy
        /// </summary>
        /// <param name="i_EnergyToFill">how much energy to fill</param>
        protected void FillEnergy(float i_EnergyToFill)
        {
            if (i_EnergyToFill < k_MinEnergy)
            {
                string exceptionMessage = "You cannot fill Energy below Min - " + k_MinEnergy;
                throw new ValueOutOfRangeException(k_MinEnergy, r_MaxEnergy, exceptionMessage);
            }
            else if (m_CurrentEnergy + i_EnergyToFill > r_MaxEnergy)
            {
                string exceptionMessage = "You cannot fill above Max Energy - " + r_MaxEnergy;
                throw new ValueOutOfRangeException(k_MinEnergy, r_MaxEnergy, exceptionMessage);
            }
            else
            {
                m_CurrentEnergy += i_EnergyToFill;
            }
        }
    }
}
